import fs from "fs"
import path from "path"

export const findUp = (filename: string): string => {
  let currentDir = path.resolve('.');
  let prevCurrentDir = null;
  while(prevCurrentDir != currentDir) {
    if (fs.existsSync(path.join(currentDir, filename))) {
      return path.join(currentDir, filename);
    }
    prevCurrentDir = currentDir;
    currentDir = path.dirname(currentDir);
  }
  throw new Error(`${filename} not found in any dir above current`);
}

